package com.saydc.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;

import com.saydc.model.Expertise;
import com.saydc.utils.HibernateUtils;

public class ExpertiseDAO {
	
	private static ExpertiseDAO instance;

	public static ExpertiseDAO getInstance(){
		if(instance == null){
			instance = new ExpertiseDAO();
		}
		return instance;
	}
	
	@SuppressWarnings("unchecked")
	public ArrayList<Expertise> getExpertises(){
		ArrayList<Expertise> listaExpertises = new ArrayList<Expertise>();
		Session session = HibernateUtils.currentSession();
		listaExpertises.addAll(session.createQuery("select e from Expertise e").list());
		return listaExpertises;
	}

	public Expertise getExpertiseFromLista(List<Expertise> listaExpertises,	int idExpertise) {
		Expertise expertiseBuscado = null;
		for(Expertise expertise : listaExpertises){
			if(expertise.getIdExpertise() == idExpertise){
				expertiseBuscado = expertise;
			}
		}
		return expertiseBuscado;
	}

}
